package com.apobates.jforum2.troll.notices.mapper;

import com.apobates.jforum2.troll.notices.entity.ForumLetter;
import com.apobates.jforum2.troll.notices.stub.vo.LetterDigestVo;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityBiTransformMapper;
import java.util.Optional;
import java.util.function.BiFunction;


public class LetterDigestVoMapperEntity implements OptionalEntityBiTransformMapper<ForumLetter, Long, LetterDigestVo> {

    public static BiFunction<ForumLetter, Long, LetterDigestVo> mapper(){
        return (forumLetter,receiver)->{
            LetterDigestVo dv = new LetterDigestVo();
            dv.setId(forumLetter.getId());
            dv.setSubject(forumLetter.getTitle());
            dv.setBody(forumLetter.getContent());
            dv.setEntryDatetime(forumLetter.getEntryDateTime());
            dv.setSender(forumLetter.getAuthor());
            dv.setNickname(forumLetter.getNickname());
            dv.setReceiver(receiver);
            return dv;
        };
    }

    @Override
    public Optional<LetterDigestVo> transform(Optional<ForumLetter> entity, Long param) {
        return entity.map(ins->{
            return mapper().apply(ins, param);
        });
    }
}
